$(document).ready(function(){
	$("#getCode").click(function(){
		$(this).unbind("click");
		timedCount();
		changeCode.getSmsCode();
    });
    var $ph_num = $("#ph-num");
    $ph_num.keyup(function(){
        var val = $(this).val();
        if(val ==''){
            $(this).css("color","black");
        }else{
            changeCode.CheckMobile(val);
        }
    });
});
var c= 60;
var t;
function timedCount(){
    document.getElementById("getCode").innerHTML = c;
    c= c-1;
    if(c === 0){
        document.getElementById("getCode").innerHTML = "获取验证码";
        $("#getCode").removeAttr("disabled");
        $("#getCode").bind("click");
        c = 60;
        return 0 ;
    }
    t= setTimeout("timedCount()",1000);
}
var changeCode = $.extend({
	getSmsCode:function(){
		var Ph_num = $("#ph-num").val();
        var Post = "mid="+Ph_num;
        $.ajax({
        	url:'../api/account/sendCode',
        	type:'post',
        	data:Post,
        	success:function(msg){
        	}
        });
	},
	setNewPsw:function(){
		var Ph_num = $("#ph-num").val();
		var authCode = $("#auth-code").val();
		var newPsw = $("#new-psw").val();
        var Post ="mid="+Ph_num+"&newpaswd="+newPsw+"&smscode="+authCode;
        $.ajax({
        	url:'../api/account/findpaswdbymidandcode',
        	type:'post',
        	data:Post,
        	success:function(msg){
        		if(msg.responseCode ===100){
        			window.location = "Login.html";
        		}
        	}
        });
	},
    CheckMobile:function(str){
        var rule = /^1\d{10}$/;
        if(rule.test(str)){
            $("#ph-num").css("color","green");
        }else{
            $("#ph-num").css("color","red");
        }
    }
});